define(function(require, exports, module) {
    "use strict";
    var $ = require("$"),
        config = require("./setting"),
         method = require("./method"),
        plugin = require("./plugins");

    var logtmp = require("./tmp/logtmp.html")
    return {

        init: function(options, e) {
            var $el = $(e.target),
                force = $el.data("force");
            if (!force) {
                //过滤 tr中的标签点击事件
                if ($(method.eventarget(e)).closest("input,textarea,button,select,option,a").length) {
                    return true;
                }
            }; 
            this.options = $.extend(true, {}, options);
            var enp = $(".entity-panel");
            enp.length && enp.trigger('close');
            if (this.options.path) {
                $.ajax(this.options.path, {
                    type: "get",
                    dataType: "html",
                    data: options.set
                }).done(function(result) {
                    var $result = $(result);
                    $("body").append($result);
                    plugin.init($result)
                    $result.removeClass("hd").animate({
                        right: 0
                    }, "fast")
                    $result.bind('close', function() {
                        $result.animate({
                            right: "-35%"
                        }, "fast", function() {
                            $result.remove()
                        });
                        options.onClose && options.onClose();
                    });
                    var $operlog = $(".js_operlog", $result)
                    if ($operlog.length > 0) {
                        var path = $operlog.data("path");
                        if (path) {
                            $operlog.scrollPage({
                                selector: ".contact_log_items li:last",
                                path: path,
                                data: {
                                    count: 40
                                }
                            }, function(element, result) {
                                element.scrollPage("toggleDone", result.is_continue);
                                if (result.list && result.list.length > 0) {
                                    $(".contact_log_items", $operlog).append(template.compile(logtmp)(result))
                                }; 
                            })
                        };

                    };
                }).fail(function() {
                    config.msg.info(config.lang.exception);
                }).always(function() {
                    options.onShow && options.onShow();
                })
            } else {
                config.msg.info(config.lang.exception);
                console.error(config.lang.pathError);
            }
        }

    }

})
